Tool Results
Every BindAI tool execution produces aToolResult.
ToolResult is the standard result object used by the Tool abstraction. It records whether execution succeeded, the value returned by the underlying Python function, and any error information produced during execution.
This provides a predictable contract between tool execution and the rest of the framework.
ToolResult
ToolResult is a dataclass with three fields:
ToolResult uses slots=True.
The important distinction is that value contains successful tool output, while error contains the error information for failed execution.
How Tool Results Are Created
Tools automatically convert function execution into aToolResult.
For example:
ToolResult manually.
Successful Execution
When the underlying function completes successfully,Tool wraps its return value in a successful result.
Conceptually:
result.value.
Failed Execution
If the underlying function raises an exception, theTool abstraction converts the exception into a failed ToolResult.
Conceptually:
Checking Success
Applications can inspect thesuccess field:
Accessing the Returned Value
A successful tool return value is stored invalue.
For example:
value, not output.
This distinction is important because AgentResult uses a different result interface.
Returning Different Python Values
A tool can return normal Python values.Strings
Numbers
Lists
Dictionaries
ToolResult.value field accepts arbitrary Python values, so the underlying tool can return different value types.
Choose return types that are useful and predictable for the application.
None as a Tool Value
A tool can also complete successfully without returning a meaningful value.
For example:
value=None by itself as a failure.
Use result.success to determine whether execution succeeded.
Tool Exceptions
Tool exceptions are handled by theTool abstraction.
An exception raised by the underlying function is converted into a failed ToolResult.
The resulting error information is derived from the exception.
Conceptually:
ToolExecutor
BindAI also providesToolExecutor.
ToolExecutor works with a ToolRegistry:
ToolResult.
This provides a lower-level execution path that does not require going through a complete agent request.
Unknown Tools
IfToolExecutor cannot find the requested tool in its registry, it returns a failed ToolResult.
The result represents the failed lookup:
ToolResult interface:
Tool Execution Flow
The current tool execution flow can be summarized as:ToolExecutor:
ToolResult and Agents
ToolResult is specifically concerned with tool execution.
AgentResult represents the result of an agent execution.
They have different responsibilities and different APIs.
For example, a tool result uses:
AgentResult interface described in the Agent execution and Results documentation.
Do not assume that fields from one result type are available on the other.
In particular:
ToolResult API.
ToolResult and Workflows
Tools can also be used as part of workflow execution. A workflow can invoke a tool, inspect its result, and use the successful value in subsequent processing. Conceptually:ToolResult itself remains focused on the outcome of the individual tool execution.
ToolResult and External Integrations
Tools commonly wrap external operations such as:- API requests
- Database operations
- File operations
- Search operations
- Notifications
- Service integrations
Current API
The currently verifiedToolResult API is:
Result Handling Pattern
A simple result-handling pattern is:Predictable Tool Outputs
Tool outputs should be designed with their callers in mind. Prefer predictable structures for operations that return structured information. For example:Error Messages
Error messages should provide useful information without exposing sensitive implementation details. For example:- API keys
- Access tokens
- Passwords
- Connection strings
- Sensitive personal information
- Internal credentials
Best Practices
- Return normal Python values from tool functions.
- Let
Toolwrap successful return values intoToolResult. - Check
result.successbefore usingresult.value. - Inspect
result.errorwhen execution fails. - Keep tool return values predictable.
- Use clear and useful error messages.
- Avoid exposing secrets or sensitive internal details through errors.
- Keep tool functions focused on one responsibility.
- Test both successful and failed execution.
- Test unknown-tool behavior when using
ToolExecutor. - Do not rely on an
outputfield forToolResult; usevalue. - Do not assume
ToolResultandAgentResulthave identical APIs. - Do not depend on undocumented result helper methods.
Complete Example
AgentResult, while the individual tool execution uses ToolResult.
When working directly with a ToolResult, the successful tool value is accessed through:
Summary
ToolResult is BindAI’s standard result object for tool execution.
The current result structure is:
value.
An execution failure is represented by success=False and error information in error.
The current public interface is intentionally small:
